#include "main/utils.h"
using namespace std;

bool similar(const vector<string>& strs, int i, int j) {
  int diff_num = 0;
  for (int k = 0; k < strs[i].size(); ++k) {
    if (strs[i][k] != strs[j][k]) {
      ++diff_num;
    }
  }
  return diff_num <= 2;
}

int findFather(vector<int>& fathers, int i) {
  if (fathers[i] != i) {
    fathers[i] = findFather(fathers, fathers[i]);
  }
  return fathers[i];
}

bool merge(vector<int>& fathers, int i, int j) {
  int father_i = findFather(fathers, i);
  int father_j = findFather(fathers, j);
  if (father_i != father_j) {
    fathers[father_i] = father_j;
    return true;
  }
  return false;
}

int numOfSimilarStrs(const vector<string> strs) {
  int num = strs.size();
  vector<int> fathers;
  for (int i = 0; i < num; ++i) {
    fathers.push_back(i);
  }
  int count = num;
  for (int i = 0; i < num; ++i) {
    for (int j = i + 1; j < num; ++j) {
      if (similar(strs, i, j) && merge(fathers, i, j)) {
        --count;
      }
    }
  }
  return count;
}

int main() {
  vector<string> strs = {"tars", "rats", "arts", "star"};
  cout << numOfSimilarStrs(strs) << endl;

  return 0;
}
